<?php
header("Content-type: text/html; charset=utf-8");
ignore_user_abort(true); // 后台运行，不受前端断开连接影响
set_time_limit(0);
ini_set('max_execution_time', '0');
chdir(dirname(__FILE__));
error_reporting(E_ERROR);
require_once ('../log.php');

LOGINFO("================== 开始");
// LOGINFO($_GET, "=== _GET");
// LOGINFO($_POST, "=== _POST");
require_once ('api_accept_oper.php');
// require_once ("api_tool.php");
header('content-type:application:json;charset=utf8');
header('Access-Control-Allow-Origin:*');
header('Access-Control-Allow-Methods:POST');
header('Access-Control-Allow-Headers:x-requested-with,content-type');

if (empty($_POST)) {
	$_Data = $_GET;
} else {
	$_Data = $_POST;
}

/** 
 * @name Api接口demo（php版）
 * @desc 本接口列表，仅仅是以php语言为例封装的API，其他语言自行参考其中一个即可，无依赖，且大同小异
 * @link www.keaimao.com
 * @author winn bug反馈 新功能定制请联系QQ：1525555556
 * @version 3.0
 * @copyright by lovelycat team
 */

// LOGINFO($_Data, '=== $_Data');
// define("AppSecret", "oudadi");
$sign = $_Data['sign'];
if(strlen($sign) <= 0) {
	echo json_encode(array(
		'state' => -1,
		'msg'	=> '缺少数据'
	));
	exit;
}

$post_params = array();
foreach ($_Data as $k => $v) {
    if ($k != 'sign') {
        $stringToBeSigned .= "$k$v";
        $post_params[$k] = $v;
    }
}

$server_sign = generateSign($post_params);
if($server_sign != $sign) {
	echo json_encode(array(
		'state' => -1,
		'msg'	=> '格式错误',
	));
	exit;
}

$fun = $_Data['fun'];
if (!empty($fun)) {
	// LOGINFO($fun, "=== fun");
	// $rt = call_user_func($fun, $_Data);
	// LOGINFO($rt, "=== rt");
	// echo json_encode($rt);
	echo json_encode(call_user_func($fun, $_Data));
}

LOGINFO("================== 结束！");
exit;
?>